//
//  LTViewController.m
//  中关村在线
//
//  Created by hy on 16/1/9.
//  Copyright © 2016年 hongyu. All rights reserved.
//

#import "LTViewController.h"
#import "TopCollectionViewCell.h"
#import "LTCollectionViewCell.h"
@interface LTViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, retain) UICollectionView *collection;
@property (nonatomic, retain) UICollectionView *TopCollection;
@end

@implementation LTViewController

- (void)dealloc {
    [_TopCollection release];
    [_collection release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.barStyle = UIStatusBarStyleLightContent;
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:12 / 255.0 green:118 / 255.0 blue:255 / 255.0 alpha:1];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    [self creatItem];
    [self createCollection];
    [self createTopCollection];
}
- (void)creatItem {
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:nil];
    self.navigationItem.rightBarButtonItem = item;
    [item release];
}
- (void)createCollection {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(375, 667);
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:layout];
    _collection.pagingEnabled = YES;
    [self.view addSubview:_collection];
    _collection.delegate = self;
    _collection.dataSource = self;
    [_collection registerClass:[LTCollectionViewCell class] forCellWithReuseIdentifier:@"LTCell"];
    [_collection release];
    [layout release];
}
- (void)createTopCollection {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake((375 / 2 - 15) / 2, 30);
    layout.minimumInteritemSpacing = 5;
    layout.minimumLineSpacing = 5;
    layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.TopCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(150, 20, 375 / 2, 40) collectionViewLayout:layout];
    self.navigationItem.titleView = _TopCollection;
    _TopCollection.backgroundColor = [UIColor colorWithRed:12 / 255.0 green:118 / 255.0 blue:255 / 255.0 alpha:1];
    _TopCollection.delegate = self;
    _TopCollection.dataSource = self;
    [_TopCollection registerNib:[UINib nibWithNibName:@"TopCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"TopCell"];
    [_TopCollection release];
    [layout release];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (collectionView == _TopCollection) {
        return 2;
    }
    else if (collectionView == _collection) {
        return 2;
    }
    return 0;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
   
    if (collectionView == _collection) {
        LTCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LTCell" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor whiteColor];
        return cell;
    }
    else if (collectionView == _TopCollection) {
        TopCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TopCell" forIndexPath:indexPath];
        NSArray *array = @[@"热帖", @"板块"];
        cell.textLabel.text = array[indexPath.row];
        cell.textLabel.textAlignment = NSTextAlignmentCenter;
        cell.textLabel.textColor = [UIColor whiteColor];
        return cell;
    }
    return nil;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
